package com.luo;

import javafx.scene.control.Alert;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @author luoqingchen
 * @reate 2022-11-22-23:25
 */
public class refl {
    public static void main(String[] args) {
        try {
            Class<?> aClass = Class.forName("com.luo.User");
            Class<?> superclass = aClass.getSuperclass();

            Constructor<?> declaredConstructor = aClass.getDeclaredConstructor();
            System.out.println(declaredConstructor);
            declaredConstructor.setAccessible(true);//打破jdk安全检查  提高反射速度

            Method[] declaredMethod = aClass.getDeclaredMethods();
            for (int i = 0; i < declaredMethod.length; i++) {
                System.out.println(declaredMethod[i]);

            }
            System.out.println("============================");
            Field[] declaredFields = aClass.getDeclaredFields();
            for (int i = 0; i < declaredMethod.length; i++) {
                System.out.println(declaredFields[i]);

            }

        } catch (ClassNotFoundException | NoSuchMethodException e) {
            e.printStackTrace();
        }
    }
}
